var play = {
	"oBack" : document.getElementById("back"),
	"back" : document.getElementsByClassName("back")[0],
	"oSec" : document.getElementById("sec"),
	"oLev" : document.getElementById("level"),
	"oSta" : document.getElementById("start"),
	"oUl" : document.getElementById("oul"),
	"oLi" : document.getElementById("li1"),
	"level" : 1,
	"time" : 30.00,
	"n" : 1,
	// 初始化
	"init" : function(){
		this.start();
		this.restart();
	},
	// 开始
	"start" : function(){
		var This = this;
		This.oLev.innerHTML = This.n;
		This.oSta.onclick = function(){
			This.oSta.remove();
			This.oLi.remove();
			This.timed();
			This.add();
			document.getElementById('music').play();
		}
	},
	// 重新开始
	"restart" : function(){
		var This = this;
		this.oBack.onclick = function(){
			This.oBack.parentNode.style.display = "none";
			This.n = 1;
			This.level = 1;
			This.time = 30.00;
			var alli = This.oUl.querySelectorAll("li");
			for (var i = 0; i < alli.length; i++) {
				alli[i].remove();
			}
			This.timed();
			This.add();
			document.getElementById('music').play();
			
		}
	},
	// 游戏倒计时
	"timed" : function(){
		var This = this;
		var timer = setInterval(function(){
			This.time = (This.time-0.02).toFixed(2);
			This.oSec.innerHTML = This.time;
			if(This.time <= 0){
				clearInterval(timer);
				if(This.n < 8){
					alert("睁眼瞎");
					
				}else if(This.n >= 20){
					alert("找不到词语形容你非人类的眼睛");
				
				}else if(This.n >= 12){
					alert("火眼金睛");
					
				}else{
					alert("高度近视");
					
				}
				This.oBack.parentNode.style.display = "block";
				document.getElementById('music').pause();
				console.log(1)
			}
			
		},20);
	},
	// 添加图片
	"add" : function(){
		this.level++;
		this.oLev.innerHTML = this.n;
		var aw = this.oUl.offsetWidth;
		for (var i = 0; i < this.level*this.level; i++) {
			var newLi = document.createElement("li");
			newLi.style.float = "left";
			newLi.style.width = aw/this.level + "px";
			newLi.style.height = aw/this.level + "px";
			newLi.style.backgroundColor = "rgb("+this.randcolor(255)+","+this.randcolor(255)+","+this.randcolor(255)+")";
			this.oUl.appendChild(newLi);
			var newImg = document.createElement("img");
			newImg.style.width = aw/this.level + "px";
			newImg.style.height = aw/this.level + "px";
			newImg.src = "1.png";
			newLi.appendChild(newImg);
		}
		var ran = this.randcolor(this.level*this.level);
		var alli = this.oUl.querySelectorAll("li");
		var oImg = alli[ran].children[0];
		oImg.src = "2.png";
		var This = this;
		alli[ran].onclick = function(){
			This.n++;
			for (var i = 0; i < alli.length; i++) {
				alli[i].remove();
			}
			if(This.level >= 11)
				This.level = 11; 
			This.add();
		}
	},
	// 生成随机数
	"randcolor" : function(num){
		return Math.floor(Math.random()*num);
	}
}